package org.rc.web;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import java.util.List;

/**
 * Data bean for jquery datatables
 * see http://datatables.net/usage/server-side
 * Inteded to be unmarshalled as json
 * 
 * @author dokeeffe
 */
public abstract class JqueryDataTablePage<T> {
    
    /**
     * An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
     */
    @Expose
    private int sEcho;
    /**
     * Total records, before filtering (i.e. the total number of records in the database)
     */
    @Expose
    private String iTotalRecords;
    /**
     * Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)
     */
    @Expose
    private String iTotalDisplayRecords;
    /**
     * The data in a 2D array. 
     */
    @Expose
    private List<List<String>> aaData;

    /**
     * Implement this in concrete classes to load the data from a list of your model class
     * @param data 
     */
    public abstract void loadTable(List<T> data);
    
    public String asJson() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }
    
    
    /**
     * @param iTotalRecords the iTotalRecords to set
     */
    public void setiTotalRecords(Integer iTotalRecords) {
        this.setiTotalRecords(""+iTotalRecords);
    }

    /**
     * An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
     * @return the sEcho
     */
    public int getsEcho() {
        return sEcho;
    }

    /**
     * An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
     * @param sEcho the sEcho to set
     */
    public void setsEcho(int sEcho) {
        this.sEcho = sEcho;
    }

    /**
     * Total records, before filtering (i.e. the total number of records in the database)
     * @return the iTotalRecords
     */
    public String getiTotalRecords() {
        return iTotalRecords;
    }

    /**
     * Total records, before filtering (i.e. the total number of records in the database)
     * @param iTotalRecords the iTotalRecords to set
     */
    public void setiTotalRecords(String iTotalRecords) {
        this.iTotalRecords = iTotalRecords;
    }

    /**
     * Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)
     * @return the iTotalDisplayRecords
     */
    public String getiTotalDisplayRecords() {
        return iTotalDisplayRecords;
    }

    /**
     * Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)
     * @param iTotalDisplayRecords the iTotalDisplayRecords to set
     */
    public void setiTotalDisplayRecords(String iTotalDisplayRecords) {
        this.iTotalDisplayRecords = iTotalDisplayRecords;
    }

    /**
     * The data in a 2D array.
     * @return the aaData
     */
    public List<List<String>> getAaData() {
        return aaData;
    }

    /**
     * The data in a 2D array.
     * @param aaData the aaData to set
     */
    public void setAaData(List<List<String>> aaData) {
        this.aaData = aaData;
    }
    
}
